import { ref } from 'vue'
import { getId } from '../utils/config'
import axios from 'axios'
export default function newTodo(todoList) {
    const todoTitle = ref('');
    let addTodo = () => {
        let result = todoTitle.value.trim();
        if (!result) {
            return
        }
        let value = {
            id: getId(),
            completed: 0,
            content: result
        }
        todoList.value.push(value);
        axios.post('http://114.132.210.22:4000/addItem', { item: value })
        todoTitle.value = '';
    }
    return {
        todoTitle,
        addTodo
    }
}